/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.inventory.controllers;

import com.inventory.entities.CustomerDetails;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author sithum
 */
@Stateless(mappedName = "CustomerDetailsController")
public class CustomerDetailsControllerBean implements CustomerDetailsControllerRemote {

    /*
     * Injects the specified Persistence unit to the EntityManager associated
     * with the current transaction.
     */
    @PersistenceContext(unitName = "SaicssPU")
    private EntityManager em;

    public List<CustomerDetails> findAll() {
        return em.createNamedQuery("CustomerDetails.findAll").getResultList();
    }

    /**
     * Returns the number of records in the Customer_Details relation.
     * @return
     */
    public int count() {
        return Integer.valueOf(em.createNamedQuery("CustomerDetails.recordCount").getSingleResult().toString()).intValue();
    }

    /**
     * Returns the specific Customer details record using the contact number
     * provided.
     * @param java.lang.String contact
     * @return com.inventory.entities.CustomerDetails
     */
    public CustomerDetails findByTelephone(String contact) {
        Query findByContact = em.createNamedQuery("CustomerDetails.findByCustomerContact");
        return (CustomerDetails) findByContact.setParameter("customerContact", contact).getSingleResult();
    }

}
